package com.mach.platform.service.js.iot;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * 生产设备工厂
 */
public class ModelDevFactory {

    protected static Map<Integer,GeneralModelDev> devMaps = new HashMap<Integer,GeneralModelDev>();

    public static GeneralModelDev getOrNew(Map<String, Object> devInfoMap, IOTJsService iot) {
        Integer devId = Integer.parseInt(devInfoMap.get("devId").toString());
//        Integer devId = ((Long)devInfoMap.get("devId")).intValue();
        Map<String, Object> devInfo = devInfoMap;

        GeneralModelDev dev;


        dev = devMaps.get(devId);

        if(dev == null){
            dev = new SimpleModelDev(devInfoMap,iot);
        }

        if(dev !=null){

            devMaps.put(devId, dev);
        }

        dev.updateDevInfo(devInfo);
        return dev;
    }

    public static GeneralModelDev getById(Integer devId) {
        return devMaps.get(devId);
    }
}
